<template>
  <div class="check_in">
    <van-popup
      v-model:show="isShow"
      :close-on-click-overlay="false"
    >
      <div class="popup_bg">
        <div class="login_header">
          <img src="@/assets/img/yx_logo.png">
        </div>
        <div class='success'>
          <div class="title">签到成功</div>
          <div>以下是您的签到信息</div>
        </div>
        <div style="margin-top: 10px" :class="userMsg.company_level == '非会员单位' ? 'lowLevel' : 'tallLevel'">
          {{ userMsg.company_level }}
        </div>
        <div class="line_top">
          {{ userMsg.company_name }}
        </div>
        <div class="line_top" style="font-size: 18px; font-weight: bold;margin-bottom: 10px;">
          {{ userMsg.username }}
        </div>
        <div
          class="line_top"
          :class="userMsg.sign_up == '未报名' ? 'sign_color' : ''"
          style="margin-bottom: 10px"
        >
          {{ userMsg.sign_up }}
        </div>
      </div>
      <img
        class="close"
        @click="confirm"
        src="@/assets/img/close.png"
      >
    </van-popup>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { userSignIn } from '@/api/index'
import { useRoute, useRouter } from 'vue-router'
import { useStore } from 'vuex'
const route = useRoute()
const router = useRouter()
const store = useStore()
const userMsg: any = ref({})
const isShow = ref(false)

const dialogAlert = () => {
  if (sessionStorage.getItem('goBackUrl')) {
    sessionStorage.removeItem('goBackUrl')
  }
  store.dispatch('fetchUserInfo').then(() => {
    const id = route.query.activity_id
    const userId = store.state.userInfo.id
    userSignIn({ activity_id: id, user_id: userId }).then((res: any) => {
      userMsg.value = res
      isShow.value = true
    }).catch((err: any) => {
      console.log('err', err)
      // router.replace({
      //   path: '/home'
      // })
      // userMsg.value = res
      isShow.value = true
    })
  })
}

const confirm = () => {
  router.replace({
    path: '/home'
  })
}

dialogAlert()
</script>

<style lang="less">
.lowLevel {
  color: #fff;
  background-color: #999;
  display: inline;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 12px;
}
.tallLevel {
  color: #fff;
  background-color: #f7783c;
  display: inline;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 12px;
}
.success {
  margin: 10px 0;
  padding: 10px;
  border-bottom: 1px solid #f5f5f5;
  .title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 10px;
  }
}
  .check_in {
    background-color: #fff;
    .register {
      width: 224px;
      height: 298px;
      border-radius: 20px;
      object-fit: cover;
    }
    .van-popup {
      background: initial;
      width: 63%;
    }

    .popup_bg {
      background-color: #fff;
      padding: 30px 26px;
      border-radius: 10px;
      text-align: center;
      line-height: 20px;
      // line-height: 42px;
    }

    .sign_color {
      color: red;
    }

    .line_top {
      margin-top: 20px;
    }
    .close {
      width: 30px;
      height: 30px;
      object-fit: cover;
      margin: 0 auto;
      padding-top: 10px;
    }
    .login_header {
      width: 100%;
      object-fit: cover;
      img {
        width: 100%;
      }
    }
  }

@media (min-width: 750px) {
  .check_in {
    background-color: #fff;
    .register {
      width: 224px;
      height: 298px;
      border-radius: 20px;
      object-fit: cover;
    }
    .van-popup {
      background: initial;
      width: 63%;
    }

    .line_top {
      margin-top: 20px;
    }
    .popup_bg {
      background-color: #fff;
      padding: 30px 26px;
      border-radius: 10px;
      text-align: center;
      line-height: 20px;
      // line-height: 42px;
    }

    .close {
      width: 30px;
      height: 30px;
      object-fit: cover;
      margin: 0 auto;
      padding-top: 10px;
    }
    .login_header {
      width: 100%;
      object-fit: cover;
      img {
        width: 100%;
      }
    }
  }
}
</style>
